﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[usp_update_uddi_admin]
	-- Add the parameters for the stored procedure here
	@smtpserver  varchar(50),
	@notificationemail varchar(100),
	@notificationenabled bit,
	@autopublish bit,
	@contactname varchar(50),
	@contactemail varchar(50),
	@ID int,
	@SMTPFromEmail varchar(50),
	@SMTPSubject varchar(255),
	@SMTPBody varchar(255),
	@UDDIServer varchar(255),
	@Anonymous bit,
	@ServiceInterval int,
	@CategorySchema varchar(255),
	@LdapRoot varchar(255)
	AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @ErrorCode int;
	SET @ErrorCode = 0;

    -- Insert statements for procedure here
	if exists(select * from UDDI_Admin where ID = @ID)
		UPDATE UDDI_ADMIN
		SET 
				SMTPServer =@smtpserver,
				NotificationEmail =@notificationemail,
				NotificationEnabled =@notificationenabled,
				Autopublish =@autopublish,
				ContactName = @contactname,
				ContactEmail = @contactemail,
				SMTPFromEmail = @SMTPFromEmail,
				SMTPSubject = @SMTPSubject,
				SMTPBody = @SMTPBody,
				UDDIServer = @UDDIServer,
				Anonymous = @Anonymous,
				ServiceInterval = @ServiceInterval,
				CategorySchema = @CategorySchema,
				LdapRoot = @LdapRoot

		WHERE 
				ID = @ID
	else
		INSERT  INTO UDDI_ADMIN
			(ID, SMTPServer, NotificationEmail, 
			NotificationEnabled, AutoPublish, Contactname, ContactEmail, SMTPFromEmail,
			SMTPSubject, SMTPBody, UDDIServer, Anonymous, ServiceInterval, CategorySchema, LdapRoot)
		VALUES (@ID, @smtpserver, @notificationemail,
			@notificationenabled, @autopublish, @contactname, @contactemail,@SMTPFromEmail,
			@SMTPSubject, @SMTPBody, @UDDIServer, @Anonymous, @ServiceInterval, @CategorySchema, @LdapRoot)

	SET @ErrorCode = @@Error;

	IF (@ErrorCode <> 0) GOTO ERROR_HANDLER;
	
	RETURN 0;

ERROR_HANDLER:
IF (@ErrorCode <> 0)
BEGIN
	RETURN 1
END
END
